

<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
  <meta charset="utf-8" />
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  
  <title>用命令行配置 iSCSI Target &mdash; Ceph Documentation</title>
  

  
  <link rel="stylesheet" href="../../_static/ceph.css" type="text/css" />
  <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
  <link rel="stylesheet" href="../../_static/graphviz.css" type="text/css" />
  <link rel="stylesheet" href="../../_static/css/custom.css" type="text/css" />

  
  
    <link rel="shortcut icon" href="../../_static/favicon.ico"/>
  

  
  

  

  
  <!--[if lt IE 9]>
    <script src="../../_static/js/html5shiv.min.js"></script>
  <![endif]-->
  
    
      <script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script>
        <script src="../../_static/jquery.js"></script>
        <script src="../../_static/underscore.js"></script>
        <script src="../../_static/doctools.js"></script>
    
    <script type="text/javascript" src="../../_static/js/theme.js"></script>

    
    <link rel="index" title="Index" href="../../genindex/" />
    <link rel="search" title="Search" href="../../search/" />
    <link rel="next" title="手动安装 ceph-iscsi" href="../iscsi-target-cli-manual-install/" />
    <link rel="prev" title="用 Ansible 配置 iSCSI Target" href="../iscsi-target-ansible/" /> 
</head>

<body class="wy-body-for-nav">

   
  <header class="top-bar">
    

















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="../../" class="icon icon-home"></a> &raquo;</li>
        
          <li><a href="../">Ceph 块设备</a> &raquo;</li>
        
          <li><a href="../rbd-integrations/">Ceph 块设备与第三方对接</a> &raquo;</li>
        
          <li><a href="../iscsi-overview/">Ceph iSCSI Gateway</a> &raquo;</li>
        
          <li><a href="../iscsi-targets/">iSCSI Targets</a> &raquo;</li>
        
      <li>用命令行配置 iSCSI Target</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
          
            <a href="../../_sources/rbd/iscsi-target-cli.rst.txt" rel="nofollow"> View page source</a>
          
        
      </li>
    
  </ul>

  
  <hr/>
</div>
  </header>
  <div class="wy-grid-for-nav">
    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search"  style="background: #eee" >
          

          
            <a href="../../">
          

          
            
            <img src="../../_static/logo.png" class="logo" alt="Logo"/>
          
          </a>

          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../search/" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        
        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../../start/intro/">Ceph 简介</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../install/">安装 Ceph</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../cephadm/">Cephadm</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../rados/">Ceph 存储集群</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../cephfs/">Ceph 文件系统</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="../">Ceph 块设备</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="../rados-rbd-cmds/">基本命令</a></li>
<li class="toctree-l2"><a class="reference internal" href="../rbd-operations/">运维</a></li>
<li class="toctree-l2 current"><a class="reference internal" href="../rbd-integrations/">对接</a><ul class="current">
<li class="toctree-l3"><a class="reference internal" href="../rbd-ko/">内核模块</a></li>
<li class="toctree-l3"><a class="reference internal" href="../qemu-rbd/">QEMU</a></li>
<li class="toctree-l3"><a class="reference internal" href="../libvirt/">libvirt</a></li>
<li class="toctree-l3"><a class="reference internal" href="../rbd-kubernetes/">Kubernetes</a></li>
<li class="toctree-l3"><a class="reference internal" href="../rbd-nomad/">Nomad</a></li>
<li class="toctree-l3"><a class="reference internal" href="../rbd-openstack/">OpenStack</a></li>
<li class="toctree-l3"><a class="reference internal" href="../rbd-cloudstack/">CloudStack</a></li>
<li class="toctree-l3 current"><a class="reference internal" href="../iscsi-overview/">LIO iSCSI Gateway</a><ul class="current">
<li class="toctree-l4"><a class="reference internal" href="../iscsi-requirements/">Requirements</a></li>
<li class="toctree-l4 current"><a class="reference internal" href="../iscsi-targets/">Configuring the iSCSI Target</a></li>
<li class="toctree-l4"><a class="reference internal" href="../iscsi-initiators/">Configuring the iSCSI Initiators</a></li>
<li class="toctree-l4"><a class="reference internal" href="../iscsi-monitoring/">Monitoring the iSCSI Gateways</a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="../rbd-windows/">Windows</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../man/">手册页</a></li>
<li class="toctree-l2"><a class="reference internal" href="../api/">APIs</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../radosgw/">Ceph 对象网关</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../mgr/">Ceph 管理器守护进程</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../mgr/dashboard/">Ceph 仪表盘</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../api/">API 文档</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../architecture/">体系结构</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../dev/developer_guide/">开发者指南</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../dev/internals/">Ceph 内幕</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../governance/">项目管理</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../foundation/">Ceph 基金会</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../ceph-volume/">ceph-volume</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../releases/general/">Ceph 版本（总目录）</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../releases/">Ceph 版本（索引）</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../security/">Security</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../glossary/">Ceph 术语</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../jaegertracing/">Tracing</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../translation_cn/">中文版翻译资源</a></li>
</ul>

            
          
        </div>
        
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../../">Ceph</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
<div id="dev-warning" class="admonition note">
  <p class="first admonition-title">Notice</p>
  <p class="last">This document is for a development version of Ceph.</p>
</div>
  <div id="docubetter" align="right" style="padding: 5px; font-weight: bold;">
    <a href="https://pad.ceph.com/p/Report_Documentation_Bugs">Report a Documentation Bug</a>
  </div>

  
  <div class="section" id="iscsi-target">
<h1>用命令行配置 iSCSI Target<a class="headerlink" href="#iscsi-target" title="Permalink to this headline">¶</a></h1>
<p>The Ceph iSCSI gateway is both an iSCSI target  and a Ceph client;
think of it as a “translator” between Ceph’s RBD interface
and the iSCSI standard. The Ceph iSCSI gateway can run on a
standalone node or be colocated with other daemons eg. on
a Ceph Object Store Disk (OSD) node.  When co-locating, ensure
that sufficient CPU and memory are available to share.
The following steps install and configure the Ceph iSCSI gateway for basic operation.</p>
<p><strong>Requirements:</strong></p>
<ul>
<li><p>A running Ceph Luminous or later storage cluster</p></li>
<li><p>Red Hat Enterprise Linux/CentOS 7.5 (or newer); Linux kernel v4.16 (or newer)</p></li>
<li><p>The following packages must be installed from your Linux distribution’s software repository:</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">targetcli-2.1.fb47</span></code> or newer package</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">python-rtslib-2.1.fb68</span></code> or newer package</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">tcmu-runner-1.4.0</span></code> or newer package</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">ceph-iscsi-3.2</span></code> or newer package</p></li>
</ul>
<blockquote>
<div><div class="admonition important">
<p class="admonition-title">Important</p>
<p>If previous versions of these packages exist, then they must
be removed first before installing the newer versions.</p>
</div>
</div></blockquote>
</li>
</ul>
<p>Do the following steps on the Ceph iSCSI gateway node before proceeding
to the <em>Installing</em> section:</p>
<ol class="arabic">
<li><p>If the Ceph iSCSI gateway is not colocated on an OSD node, then copy
the Ceph configuration files, located in <code class="docutils literal notranslate"><span class="pre">/etc/ceph/</span></code>, from a
running Ceph node in the storage cluster to the iSCSI Gateway node.
The Ceph configuration files must exist on the iSCSI gateway node
under <code class="docutils literal notranslate"><span class="pre">/etc/ceph/</span></code>.</p></li>
<li><p>Install and configure the <a class="reference external" href="../../start/quick-rbd/#install-ceph">Ceph Command-line Interface</a></p></li>
<li><p>If needed, open TCP ports 3260 and 5000 on the firewall.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>Access to port 5000 should be restricted to a trusted internal network or
only the individual hosts where <code class="docutils literal notranslate"><span class="pre">gwcli</span></code> is used or <code class="docutils literal notranslate"><span class="pre">ceph-mgr</span></code> daemons
are running.</p>
</div>
</li>
<li><p>Create a new or use an existing RADOS Block Device (RBD).</p></li>
</ol>
<p><strong>Installing:</strong></p>
<p>If you are using the upstream ceph-iscsi package follow the
<a class="reference external" href="../iscsi-target-cli-manual-install">manual install instructions</a>.</p>
<div class="toctree-wrapper compound">
</div>
<p>For rpm based instructions execute the following commands:</p>
<ol class="arabic">
<li><p>As <code class="docutils literal notranslate"><span class="pre">root</span></code>, on all iSCSI gateway nodes, install the
<code class="docutils literal notranslate"><span class="pre">ceph-iscsi</span></code> package:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><style type="text/css">
span.prompt1:before {
  content: "# ";
}
</style><span class="prompt1">yum install ceph-iscsi</span>
</pre></div></div></li>
<li><p>As <code class="docutils literal notranslate"><span class="pre">root</span></code>, on all iSCSI gateway nodes, install the <code class="docutils literal notranslate"><span class="pre">tcmu-runner</span></code>
package:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span class="prompt1">yum install tcmu-runner</span>
</pre></div></div></li>
</ol>
<p><strong>Setup:</strong></p>
<ol class="arabic">
<li><p>gwcli requires a pool with the name <code class="docutils literal notranslate"><span class="pre">rbd</span></code>, so it can store metadata
like the iSCSI configuration. To check if this pool has been created
run:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span class="prompt1">ceph osd lspools</span>
</pre></div></div><p>If it does not exist instructions for creating pools can be found on the
<a class="reference external" href="http://docs.ceph.com/en/latest/rados/operations/pools/">RADOS pool operations page</a>.</p>
</li>
<li><p>As <code class="docutils literal notranslate"><span class="pre">root</span></code>, on a iSCSI gateway node, create a file named
<code class="docutils literal notranslate"><span class="pre">iscsi-gateway.cfg</span></code> in the <code class="docutils literal notranslate"><span class="pre">/etc/ceph/</span></code> directory:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span class="prompt1">touch /etc/ceph/iscsi-gateway.cfg</span>
</pre></div></div><ol class="arabic">
<li><p>Edit the <code class="docutils literal notranslate"><span class="pre">iscsi-gateway.cfg</span></code> file and add the following lines:</p>
<div class="highlight-ini notranslate"><div class="highlight"><pre><span></span><span class="k">[config]</span>
<span class="c1"># Name of the Ceph storage cluster. A suitable Ceph configuration file allowing</span>
<span class="c1"># access to the Ceph storage cluster from the gateway node is required, if not</span>
<span class="c1"># colocated on an OSD node.</span>
<span class="na">cluster_name</span> <span class="o">=</span> <span class="s">ceph</span>

<span class="c1"># Place a copy of the ceph cluster&#39;s admin keyring in the gateway&#39;s /etc/ceph</span>
<span class="c1"># drectory and reference the filename here</span>
<span class="na">gateway_keyring</span> <span class="o">=</span> <span class="s">ceph.client.admin.keyring</span>


<span class="c1"># API settings.</span>
<span class="c1"># The API supports a number of options that allow you to tailor it to your</span>
<span class="c1"># local environment. If you want to run the API under https, you will need to</span>
<span class="c1"># create cert/key files that are compatible for each iSCSI gateway node, that is</span>
<span class="c1"># not locked to a specific node. SSL cert and key files *must* be called</span>
<span class="c1"># &#39;iscsi-gateway.crt&#39; and &#39;iscsi-gateway.key&#39; and placed in the &#39;/etc/ceph/&#39; directory</span>
<span class="c1"># on *each* gateway node. With the SSL files in place, you can use &#39;api_secure = true&#39;</span>
<span class="c1"># to switch to https mode.</span>

<span class="c1"># To support the API, the bare minimum settings are:</span>
<span class="na">api_secure</span> <span class="o">=</span> <span class="s">false</span>

<span class="c1"># Additional API configuration options are as follows, defaults shown.</span>
<span class="c1"># api_user = admin</span>
<span class="c1"># api_password = admin</span>
<span class="c1"># api_port = 5001</span>
<span class="c1"># trusted_ip_list = 192.168.0.10,192.168.0.11</span>
</pre></div>
</div>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>trusted_ip_list is a list of IP addresses on each iSCSI gateway that
will be used for management operations like target creation, LUN
exporting, etc. The IP can be the same that will be used for iSCSI
data, like READ/WRITE commands to/from the RBD image, but using
separate IPs is recommended.</p>
</div>
<div class="admonition important">
<p class="admonition-title">Important</p>
<p>The <code class="docutils literal notranslate"><span class="pre">iscsi-gateway.cfg</span></code> file must be identical on all iSCSI gateway nodes.</p>
</div>
</li>
<li><p>As <code class="docutils literal notranslate"><span class="pre">root</span></code>, copy the <code class="docutils literal notranslate"><span class="pre">iscsi-gateway.cfg</span></code> file to all iSCSI
gateway nodes.</p></li>
</ol>
</li>
<li><p>As <code class="docutils literal notranslate"><span class="pre">root</span></code>, on all iSCSI gateway nodes, enable and start the API
service:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span class="prompt1">systemctl daemon-reload</span>
<span class="prompt1"></span>
<span class="prompt1">systemctl <span class="nb">enable</span> rbd-target-gw</span>
<span class="prompt1">systemctl start rbd-target-gw</span>
<span class="prompt1"></span>
<span class="prompt1">systemctl <span class="nb">enable</span> rbd-target-api</span>
<span class="prompt1">systemctl start rbd-target-api</span>
</pre></div></div></li>
</ol>
<p><strong>Configuring:</strong></p>
<p>gwcli will create and configure the iSCSI target and RBD images and copy the
configuration across the gateways setup in the last section. Lower level
tools including targetcli and rbd can be used to query the local configuration,
but should not be used to modify it. This next section will demonstrate how
to create a iSCSI target and export a RBD image as LUN 0.</p>
<ol class="arabic">
<li><p>As <code class="docutils literal notranslate"><span class="pre">root</span></code>, on a iSCSI gateway node, start the iSCSI gateway
command-line interface:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span class="prompt1">gwcli</span>
</pre></div></div></li>
<li><p>Go to iscsi-targets and create a target with the name
iqn.2003-01.com.redhat.iscsi-gw:iscsi-igw:</p>
<div class="highlight-console notranslate"><div class="highlight"><pre><span></span><span class="go">&gt; /&gt; cd /iscsi-targets</span>
<span class="go">&gt; /iscsi-targets&gt;  create iqn.2003-01.com.redhat.iscsi-gw:iscsi-igw</span>
</pre></div>
</div>
</li>
<li><p>Create the iSCSI gateways. The IPs used below are the ones that will be
used for iSCSI data like READ and WRITE commands. They can be the
same IPs used for management operations listed in trusted_ip_list,
but it is recommended that different IPs are used.</p>
<div class="highlight-console notranslate"><div class="highlight"><pre><span></span><span class="go">&gt; /iscsi-targets&gt; cd iqn.2003-01.com.redhat.iscsi-gw:iscsi-igw/gateways</span>
<span class="go">&gt; /iscsi-target...-igw/gateways&gt;  create ceph-gw-1 10.172.19.21</span>
<span class="go">&gt; /iscsi-target...-igw/gateways&gt;  create ceph-gw-2 10.172.19.22</span>
</pre></div>
</div>
<p>If not using RHEL/CentOS or using an upstream or ceph-iscsi-test kernel,
the skipchecks=true argument must be used. This will avoid the Red Hat kernel
and rpm checks:</p>
<div class="highlight-console notranslate"><div class="highlight"><pre><span></span><span class="go">&gt; /iscsi-targets&gt; cd iqn.2003-01.com.redhat.iscsi-gw:iscsi-igw/gateways</span>
<span class="go">&gt; /iscsi-target...-igw/gateways&gt;  create ceph-gw-1 10.172.19.21 skipchecks=true</span>
<span class="go">&gt; /iscsi-target...-igw/gateways&gt;  create ceph-gw-2 10.172.19.22 skipchecks=true</span>
</pre></div>
</div>
</li>
<li><p>Add a RBD image with the name disk_1 in the pool rbd:</p>
<div class="highlight-console notranslate"><div class="highlight"><pre><span></span><span class="go">&gt; /iscsi-target...-igw/gateways&gt; cd /disks</span>
<span class="go">&gt; /disks&gt; create pool=rbd image=disk_1 size=90G</span>
</pre></div>
</div>
</li>
<li><p>Create a client with the initiator name iqn.1994-05.com.redhat:rh7-client:</p>
<div class="highlight-console notranslate"><div class="highlight"><pre><span></span><span class="go">&gt; /disks&gt; cd /iscsi-targets/iqn.2003-01.com.redhat.iscsi-gw:iscsi-igw/hosts</span>
<span class="go">&gt; /iscsi-target...eph-igw/hosts&gt;  create iqn.1994-05.com.redhat:rh7-client</span>
</pre></div>
</div>
</li>
<li><p>Set the client’s CHAP username to myiscsiusername and password to
myiscsipassword:</p>
<div class="highlight-console notranslate"><div class="highlight"><pre><span></span><span class="go">&gt; /iscsi-target...at:rh7-client&gt;  auth username=myiscsiusername password=myiscsipassword</span>
</pre></div>
</div>
<div class="admonition warning">
<p class="admonition-title">Warning</p>
<p>CHAP must always be configured. Without CHAP, the target will
reject any login requests.</p>
</div>
</li>
<li><p>Add the disk to the client:</p>
<div class="highlight-console notranslate"><div class="highlight"><pre><span></span><span class="go">&gt; /iscsi-target...at:rh7-client&gt; disk add rbd/disk_1</span>
</pre></div>
</div>
</li>
</ol>
<p>The next step is to configure the iSCSI initiators.</p>
<div class="toctree-wrapper compound">
</div>
</div>



           </div>
           
          </div>
          <footer>
    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
        <a href="../iscsi-target-cli-manual-install/" class="btn btn-neutral float-right" title="手动安装 ceph-iscsi" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
        <a href="../iscsi-target-ansible/" class="btn btn-neutral float-left" title="用 Ansible 配置 iSCSI Target" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
    </div>

  <hr/>

  <div role="contentinfo">
    <p>
        &#169; Copyright 2016, Ceph authors and contributors. Licensed under Creative Commons Attribution Share Alike 3.0 (CC-BY-SA-3.0).

    </p>
  </div> 

</footer>
        </div>
      </div>

    </section>

  </div>
  

  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script>

  
  
    
   

</body>
</html>